//
//  LBPageSmoothViewViewController.m
//  TEXT
//
//  Created by mac on 2024/8/11.
//  Copyright © 2024 刘博. All rights reserved.
//

#import "LBPageSmoothViewViewController.h"
#import "LBPageSmoothView.h"
#import "LBPageSingleController.h"
#import "LBFunctionTestHeader.h"
#import "SPPageMenu.h"
#import "LBPageListSubSegmentController.h"
#import "LBCollectionView.h"

@interface LBPageSmoothViewViewController () <
    LBPageSmoothViewDataSource,
    SPPageMenuDelegate,
    LBPageSmoothViewDelegate,
    SPPageMenuDelegate,
    LBPageListSubSegmentControllerDelegate>

@property (nonatomic, strong) LBPageSmoothView *smoothView;

@property (nonatomic, strong) UIView *headerView;

@property (nonatomic, strong) SPPageMenu *menu;

//@property (nonatomic, strong) LBPageListSubSegmentController *segmentVC;

@end

@implementation LBPageSmoothViewViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor greenColor];
//    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 400)];
//    view.backgroundColor = [UIColor redColor];
//    [self.view addSubview:view];
    [self.view addSubview:self.smoothView];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [self.smoothView reloadData];
    });
    // Do any additional setup after loading the view.
}

- (void)viewDidAppear:(BOOL)animated
{
    [self.navigationController.navigationBar setHidden:YES];
    [super viewDidAppear:animated];
   // [self.view addSubview:self.smoothView];
   // [self.smoothView reloadData];
}

/// 返回页面的headerView视图
/// @param smoothView smoothView
- (UIView *)headerViewInSmoothView:(LBPageSmoothView *)smoothView
{
    return self.headerView;
}

/// 返回需要悬浮的分段视图
/// @param smoothView smoothView
- (UIView *)segmentedViewInSmoothView:(LBPageSmoothView *)smoothView
{
    return self.menu;;
}

/// 返回列表个数
/// @param smoothView smoothView
- (NSInteger)numberOfListsInSmoothView:(LBPageSmoothView *)smoothView
{
    return 3;
}

/// 根据index初始化一个列表实例，列表需实现`GKPageSmoothListViewDelegate`代理
/// @param smoothView smoothView
/// @param index 列表索引
- (id<LBPageSmoothListViewDelegate>)smoothView:(LBPageSmoothView *)smoothView initListAtIndex:(NSInteger)index
{
    if (index == 2) {
        LBPageListSubSegmentController *vc = [[LBPageListSubSegmentController alloc] init];
        vc.delegate = self;
        vc.view;
       // self.segmentVC = vc;
        return vc;
    }
    LBPageSingleController *vc = [[LBPageSingleController alloc] init];
    return vc;
}

- (BOOL)hasSubSegmentAtIndex:(NSInteger)index
{
    if (index == 2) {
        return YES;
    }
    return NO;
}

#pragma mark - LBPageListSubSegmentControllerDelegate

- (void)containerScrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.smoothView updateUIWhenSubContainerScrollViewDidScroll];
}

- (void)containerScrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    [self.smoothView updateCurrentListViewWhenContainerDidEndDecelerating];
}

- (void)containerRemoveObserverForListView:(UIScrollView *)scrollView
{
    [self.smoothView removeObserVerForListView:scrollView];
}

#pragma mark  -  LBPageSmoothViewDelegate

- (void)smoothView:(LBPageSmoothView *)smoothView scrollViewDidScroll:(UIScrollView *)scrollView
{
    [self.menu beginMoveTrackerFollowScrollView:scrollView];
}

#pragma mark

- (void)pageMenu:(SPPageMenu *)pageMenu itemSelectedAtIndex:(NSInteger)index
{
    [self.smoothView selectIndex:index];
}

#pragma mark - lazy load

- (LBPageSmoothView *)smoothView
{
    if (!_smoothView) {
        _smoothView = [[LBPageSmoothView alloc] initWithDataSource:self];
        _smoothView.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        _smoothView.backgroundColor = [UIColor cyanColor];
        _smoothView.ceilPointHeight = 84;
        _smoothView.delegate = self;
    }
    return _smoothView;
}

- (UIView *)headerView
{
    if (!_headerView) {
        _headerView = [[LBCollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 300)];
        _headerView.backgroundColor = [UIColor purpleColor];
    }
    return _headerView;
}

- (SPPageMenu *)menu
{
    if (!_menu) {
        PageViewConfiguration *config = [[PageViewConfiguration alloc] init];
        config.titleArray = @[@"首页", @"推荐"];
        SPPageMenu *menu = [[SPPageMenu alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 40) config:config];
        [menu setItems:@[@"首页", @"推荐", @"哈哈哈"] selectedItemIndex:0];
        menu.frame = CGRectMake(0, 0, SCREEN_WIDTH, 40);
        menu.delegate = self;
        menu.backgroundColor = [UIColor greenColor];
        menu.tag = 1000;
        _menu = menu;
    }
    return _menu;
}

- (void)dealloc
{
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
